#pragma once
#include <wiringPi.h>
#include <string>
#include "easylogging++.h"

void BCC_ASCII(const char *pdata, int num, char CC[]);


class MasterSlave_RW
{
public:
    enum LStat{LS_Normal = 0, LS_BeHid_1 = 1, LS_BeHid_2 = 2, LS_BeHid_3 = 3, LS_BeHid_4 = 4, LS_BeHid_5 = 5,\
                LS_LowPower = 10,  LS_WIFIErr = 11, LS_UnsetErr = 20};
    enum TankStat{TS_Waiting = 0, TS_Normal = 1, TS_BeHid = 2, TS_Destroy = 3, TS_ACK = 99};
    enum RWStat{RWS_SPACE,RWS_TX,RWS_RX};
    static MasterSlave_RW *pMS_RW;
    static RWStat RecentRWStat;
    static TankStat m_tankStat;
    static float m_batValue;
    static float m_TurretAngle;//炮塔旋转角度  
private:
    void SendByte(char data);
    template <typename FuncData>
    std::string EncodeFuncD(std::string _func, FuncData _funcData);//组成数据包
    std::pair<std::string, int> DecodeDataF(std::string Data);
public:
    void ReadDataFromSpi(void);
    void init(void);
    void SendBytes(const char *pdata, int num);
    void SetLightStat(MasterSlave_RW::LStat stat, bool IsFrontLight = true);//默认控制的是前灯
    float ReadBAT(void);//读取电源电压
    float ReadTurretAngle(void);//读取当前的炮塔旋转角度
    void SendBeHidSignal(void);//命令下位机输出被攻击信号
    MasterSlave_RW::TankStat ReadTankStat(void);
    MasterSlave_RW();
    ~MasterSlave_RW();
};
